package main

import (
	"context"
	"google.golang.org/grpc/health"
	"google.golang.org/grpc/health/grpc_health_v1"
	"google.golang.org/grpc/reflection"
	"net"

	"github.com/namsral/flag"
	"go-demo/proto"
	"google.golang.org/grpc"
)
var addr = flag.String("addr", ":8088", "address to listen")
type Server struct{}

func (s *Server) SayHello(ctx context.Context, request *proto.HelloRequest) (*proto.HelloReply,
	error) {
	return &proto.HelloReply{
		Message: "hello " + request.Name,
	}, nil
}

func main() {
	g := grpc.NewServer()
	reflection.Register(g)
	proto.RegisterGreeterServer(g, &Server{})
	lis, err := net.Listen("tcp", *addr)
	if err != nil {
		panic("failed to listen:" + err.Error())
	}
	grpc_health_v1.RegisterHealthServer(g, health.NewServer())
	err = g.Serve(lis)
	if err != nil {
		panic("failed to start grpc:" + err.Error())
	}
}
